

const fs = require("fs")



const armorFile = "../armoranalysis/bodyarmor.html"
const retfile = "../armoranalysis/bodyarmor.js"



let armorhtmlstr = fs.readFileSync(armorFile).toString()


// (?:(?!...)[\w\W])+

let armorlists = armorhtmlstr.match(/<tr>(?:(?!<\/tr>)[\w\W])+<\/tr>/ig)

let arlists = []

armorlists.forEach(item => {

    let itemtds = item.match(/<td(?:(?!<\/td>)[\w\W])+<\/td>/ig)
    let name = /<a [^>]+>([^<]+)<\/a>/.exec(itemtds[1])[1]
    
    // 16%&#160;
    let defstr = itemtds[2]


    let tmp_phy_def = /(\d+)%&#160;/.exec(defstr) || 0
    if (tmp_phy_def) { tmp_phy_def = tmp_phy_def[1]-0 }

    let mana_cost = /data-sort-value="([^"]+)"/.exec(itemtds[11])[1] - 0
    let baohu = /data-sort-value="([^"]+)"/.exec(itemtds[5])[1] - 0
    let pinza = /data-sort-value="([^"]+)"/.exec(itemtds[6])[1] - 0

    



    arlists.push({
        name: name,
        mana_cost: mana_cost,
        baohu: baohu,
        pinza: pinza,
        def: {
            phy: tmp_phy_def
        }
    })

});





arlists = arlists.sort((b,a) => a.def.phy - b.def.phy)




fs.writeFileSync(retfile, JSON.stringify(arlists, null, 4))




























